package com.example.validproject.controller;

import com.example.validproject.entity.User;
import com.example.validproject.protocol.Result;
import com.example.validproject.valid.InsertGroup;
import com.example.validproject.valid.UpdateGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kh
 * Created by on  2021-09-27 11:30
 */
@RestController
public class UserController {

    @PostMapping("user")
    public Result saveUser(@RequestBody @Validated({InsertGroup.class}) User user) {
        user.setId(System.currentTimeMillis());
        return Result.success(user);
    }
    @PutMapping("user")
    public Result updateUser(@RequestBody @Validated({UpdateGroup.class}) User user) {
        user.setId(System.currentTimeMillis());
        return Result.success(user);
    }
}
